<script>
import {BASE_URL} from "@/util/Config.js";

  export default {
  data() {
  return {
  responseData: [], // 用于存储从后端返回的数据
    id:this.$route.params.id
};
},
  methods: {

    async fetchData() {
      const id=this.$route.params.id;
      console.log(id);
      const data = {

      };

      try {
        const response = await fetch(BASE_URL+'/service/showocomments', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(data)
        });

        if (!response.ok) {
          throw new Error('Network response was not ok ' + response.statusText);
        }

        const responseData = await response.json();
        this.response1Data = responseData.data; // 更新组件的 data 属性
        console.log(response1Data);
        // 处理响应数据
      } catch (error) {
        console.error('There was an error!', error);
      }
    },





  async sendData() {
    const id=this.$route.params.id;
    console.log(id);
  const data = {

};

  try {
  const response = await fetch(BASE_URL+'/orders', {
  method: 'POST',
  headers: {
  'Content-Type': 'application/json'
},
  body: JSON.stringify(data)
});

  if (!response.ok) {
  throw new Error('Network response was not ok ' + response.statusText);
}

  const responseData = await response.json();
  this.responseData = responseData.data; // 更新组件的 data 属性
  console.log(responseData);
  // 处理响应数据
} catch (error) {
  console.error('There was an error!', error);
}
}
},
  mounted() {
    const id=this.$route.params.id;
    console.log(id+"1");
  this.sendData();
  this.fetchData();
}
}
</script>


<template>
  <div v-if="errorMsg" class="error">{{ errorMsg }}</div>
  <div v-else>
    <div v-if="data">
      <h2>{{ data.serviceMainName }}</h2>
      <p>副标题: {{ data.serviceSubName }}</p>
      <p>适用范围: {{data.serviceScope }}</p>
      <!-- 可根据需要添加更多字段 -->
    </div>
    <div v-else>
      正在加载数据...
    </div>
  </div>
  <div class="service-info">
      <!-- 服务详情内容（数据加载完成后展示） -->




        <div v-for="item in response1Data" :key="item.id">
          <div class="comment">
            <div class="comment-header">
              <div class="comment-author">{{ item.username }}</div>
              <div class="comment-date">{{ item.commentTime }}</div>
            </div>
            <div class="comment-content">{{ item.commentContent }}</div>
          </div>
        </div>
      </div>


</template>

<style scoped>
.error {
  color: red;
}
</style>
